package zhihui.mobile.manager.express;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import zhihui.mobile.config.Config;
import zhihui.mobile.interfaces.net.IHttpCallBackListener;
import zhihui.mobile.manager.AllManagerObvs;
import zhihui.mobile.manager.IManager;
import zhihui.mobile.net.HttpUtils;

/**
 * Created by 张公铭 on 2017/7/26 0026.
 */

public class ExpressManager implements IManager {


    private static ExpressManager manager;

    private ExpressManager() {
        AllManagerObvs.getInstance().addManager(this);
    }

    private static synchronized void createdIns() {
        if (manager == null) {
            manager = new ExpressManager();
        }
    }

    public static ExpressManager getInstance() {
        if (manager == null) {
            createdIns();
        }
        return manager;
    }


    /**
     * 客户收到的包裹
     */
    public void initExpressList(IHttpCallBackListener listener, String phone) {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.wuliu.api.Package");
        params.put("method", "queryPackage");
        List<Object> list = new ArrayList<>();
        list.add(phone);

        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 派送记录
     */
    public void initExpressUnsignedRecordList(IHttpCallBackListener listener, String packageId) {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.wuliu.api.Package");
        params.put("method", "unsignedRecord");
        List<Object> list = new ArrayList<>();
        list.add(packageId);

        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 包裹历史
     */
    public void initExpressHistoryList(IHttpCallBackListener listener, int pageNum, String phone) {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.wuliu.api.Package");
        params.put("method", "showHistory");
        List<Object> list = new ArrayList<>();
        list.add(pageNum);
        list.add(20);
        list.add(phone);
        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 获取门店所有的配送时间
     */
    public void initGetShopSendTimeList(IHttpCallBackListener listener, int shopId, int isToday) {
        Map<String, String> params = new HashMap<>();
        params.put("service", "deliver");
        params.put("method", "getAllApplyTime");
        List<Object> list = new ArrayList<>();
        list.add(shopId);
        list.add(isToday);
        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 根据时间段计算价格
     */
    public void initSumPrice(IHttpCallBackListener listener, int day, int time, int packageNum) {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.wuliu.api.Package");
        params.put("method", "sumPrice");
        List<Object> list = new ArrayList<>();
        list.add(day);
        list.add(time);
        list.add(packageNum);
        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 申请获得订单号
     */
    public void initApplyOrder(IHttpCallBackListener listener, int shopDoorId, String name, String phone, String door, String shopId, int payNum, int dayTime, long timeId, long couponId) {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.wuliu.api.Package");
        params.put("method", "applyOrder");
        List<Object> list = new ArrayList<>();
        list.add(shopDoorId);
        list.add(name);
        list.add(phone);
        list.add(door);
        list.add(shopId);
        list.add(payNum);
        list.add(dayTime);
        list.add(timeId);
        list.add(couponId);
        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 查询用户的运费优惠券
     */
    public void initFindFreightCouponByUserId(IHttpCallBackListener listener, long id) {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.app.api.order.Order");
        params.put("method", "findParcelCouponByUserId");
        List<Object> list = new ArrayList<>();
        list.add(id);
        HttpUtils.postAes(Config.URL, params, list, listener);
    }


    @Override
    public void clear() {
        AllManagerObvs.getInstance().removeManager(this);
        manager = null;
    }
}
